//
//  FeedbackViewController.m
//  fitness-iOS
//
//  Created by 卢仕彤 on 2018/1/4.
//  Copyright © 2018年 卢仕彤. All rights reserved.
//

#import "FeedbackViewController.h"
#import "UIColor+Expand.h"
#import "FFGlobalHeader.h"
#import "NSString+Common.h"
#import "UITextView+FFTextView.h"
#import "FFProgressHUD.h"
#import "FFNetworkHelper.h"

@interface FeedbackViewController ()

@property (nonatomic, strong) UIView *whiteBgView;
@property (nonatomic, strong) UIButton *clearButton;

@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, copy) NSString *suggestion;

@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"意见反馈";
    [self addRightNavigationButtonWithTitle:@"确认"];
    [self.rightNavigationButton addTarget:self action:@selector(didSureButton) forControlEvents:UIControlEventTouchUpInside];
    [self configFeedbackView];
}

#pragma mark - btn action
- (void)didSureButton {
    if ([_textView.text length] == 0) {
        [FFProgressHUD showError:@"反馈意见不可为空"];
        return;
    }
    NSString *requestUrl = @"feedback/insert";
    
    [FFNetworkHelper openLog];
    NSDictionary *parmsDic = @{@"content":_textView.text};
    [FFNetworkHelper POST:requestUrl parameters:parmsDic success:^(id responseObject) {
        if ([responseObject[@"code"] integerValue] == 200) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [FFProgressHUD showSuccess:@"提交成功"];
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    } failure:^(NSError *error) {
        [FFProgressHUD showError:@"error"];
        
    }];
    
}

#pragma mark - config UI

- (void)configFeedbackView {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(0);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(186);
    }];
    
    [self.view addSubview:self.textView];
}

#pragma mark - lazy init
- (UIView *)whiteBgView {
    if (!_whiteBgView) {
        _whiteBgView = [[UIView alloc] init];
        _whiteBgView.backgroundColor = [UIColor whiteColor];
    }
    return _whiteBgView;
}

- (UITextView *)textView {
    if (!_textView) {
        _textView = [[UITextView alloc] initWithFrame:(CGRect){12, 20, CGRectGetWidth(self.view.frame)-27, 160}];
        _textView.placeholder = @"为了您更好的使用fitness，有什么意见或吐槽都可以发给我们，我们一定悉心采纳改进。";
        _textView.font = [UIFont systemFontOfSize:14];
        _textView.limitLength = @500;
    }
    return _textView;
}
@end
